Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

Security Roles

When you design an enterprise bean or Web component, you should always think about the kinds of users who will access the component. For example, a Web application for a Human Resources department might have a different request URL for someone who has been assigned the role of admin than for someone who has been assigned the role of director. The admin role may let you view some employee data, but the director role enables you to view salary information. Each of these security roles is an abstract logical grouping of users that is defined by the person who assembles the application. When an application is deployed, the deployer will map the roles to security identities in the operational environment.

A J2EE group also represents a category of users, but it has a different scope from a role. A J2EE group is designated for the entire J2EE server, whereas a role covers only a specific application in a J2EE server.

To create a role for a J2EE application, you declare it for the application EAR file. For example, you could use the following procedure to create a role with deploytool:

  1. Select an application.
  2. In the Roles tabbed pane, click Add to add a row to the table.
  3. In the Name column, enter the security role name, bankCustomer for example.
  4. Click the folded-paper icon to add a description of the security role, Customer-of-Bank for example.
  5. Click OK.

Declaring and Linking Role References

A security role reference allows an enterprise bean or Web component to reference an existing security role. A security role is an application-specific logical grouping of users, classified by common traits such as customer profile or job title. When an application is deployed, roles are mapped to security identities, such as principals (identities assigned to users as a result of authentication) or groups, in the operational environment. Based on this, a user with a certain security role has associated access rights to a J2EE application. The link is the actual name of the security role that is being referenced.

During application assembly, the assembler creates security roles for the application and associates these roles with available security mechanisms. The assembler then resolves the security role references in individual servlets and JSP pages by linking them to roles defined for the application.

The security role reference defines a mapping between the name of a role that is called from a Web component using isUserInRole(String name) (see Using Programmatic Security in the Web Tier) or from an enterprise bean using isCallerInRole(String name) (see Using Programmatic Security in the EJB Tier) and the name of a security role that has been defined for the application.

For example, use deploytool to map the security role reference cust to the security role with role name bankCustomer:

  1. Select the application.
  2. Select the Security Role Mapping tabbed pane.
  3. Select the bankCustomer entry in the Role names referenced pane. This role name would have been previously defined for the application as described in Security Roles.
  4. Click Add User/Group to Role.
  5. Select the available user name from the User name tab.
  6. Click Map to Role.
  7. Select the component that you want to create a role reference in.
  8. Select the Security tabbed pane.
  9. Select Use Caller ID (default) or Run As Role.
  10. Click Add in the Role names referenced in code pane.
  11. Enter cust in the Role name text field.
  12. Select bankCustomer in the Role Link pull-down menu.

In this example, isUserInRole("bankCustomer") and isUserInRole("cust") will both return true.

Because a coded name is linked to a role name, you can change the role name at a later time without having to change the coded name. For example, if you were to change the role name from bankCustomer to something else, you wouldn't need to change the cust name in the code. You would, however, need to relink the cust coded name to the new role name.

Mapping Roles to Users and Groups

When you are developing a J2EE application, you don't need to know what roles have been defined for the realm in which the application will be run. In the J2EE platform, the security architecture provides a mechanism for automatically mapping the roles defined in the application to the roles defined in the runtime realm. After your application has been deployed, the administrator of the J2EE server will map the roles of the application to the users, groups, or roles of the files realm.

Use deploytool to map roles defined for an application to J2EE users and/or groups:

  1. Select the J2EE application.
  2. In the Security tab, select the appropriate role from the Role Name list.
  3. Click Add.
  4. In the Users or Groups dialog box, select the users or groups that should be assigned to the selected role.
Divider
Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.